' This BASIC Anywhere Machine program by Charlie Veniot
' is a port and mod of Dav's QB64pe program
' found at https://qb64phoenix.com/forum/showthread.php?tid=1838&pid=17786#pid17786


dh = 1000
screen _newimage(1600,dh,23)
declare SUB ball (x, y, size, r, g, b)


DO
    ball (int(RND * dh)+300, int(RND * dh), int(RND * 255) + 25, int(RND * 255), int(RND * 255), int(RND * 255))
    _delay 0.1
LOOP
 
SUB ball (x, y, size, r, g, b)
    'This SUB draws a gradient ball with given color.

    'see current display status
    displayStatus%% = _AUTODISPLAY
 
    'turn off screen updates while we draw
    _DISPLAY

    reg = .4 
 
    'if size is larger than value colors given,
    'adjust the reg value to step down at a slower rate.
    'This prevents thick black rim around larger balls
    'that have a too low a given color value.
    IF size > r AND size > g AND size > b THEN
        IF r > g AND r > b THEN reg = r / size * .4
        IF g > r AND g > b THEN reg = g / size * .4
        IF b > r AND b > g THEN reg = b / size * .4
    END IF

    'now draw the ball using CIRCLE.
    'Using smaller STEP value than 1 prevents gaps.
    FOR s = 0 TO size STEP 1
        CIRCLE (x, y), s, _RGB32(r, g, b)
        CIRCLE (x+1, y), s, _RGB32(r, g, b)
        CIRCLE (x, y+1), s, _RGB32(r, g, b)
        r = max(int(r - reg),0): g = max(int(g - reg),0): b = max(int(b - reg),0)
    NEXT
    'show the ball
    _DISPLAY
 
    'If autodislay was previously on, turn it back on
    'IF displayStatus%% = 1 THEN _AUTODISPLAY
 
END SUB